import request from '@/utils/request';
import { downloadFileByData } from '@/utils/download';
import type { AxiosResponse } from 'axios';

// 定义接口类型（可根据实际后端返回结构调整）
export interface TemplateDetail {
  id?: string | number;
  [key: string]: any;
}

export interface TemplateListQuery {
  pageNo?: number;
  pageSize?: number;
  tempName_LIKE?: string;
  tableType_EQ?: string;
  [key: string]: any;
}

export function getDetailListByParentId(parentId: string | number): Promise<AxiosResponse<any>> {
  return request({
    url: '/api/v1/generator/template/detail/findListByParentId',
    method: 'get',
    params: {
      parentId,
    },
  });
}

export function getList(data: TemplateListQuery): Promise<AxiosResponse<any>> {
  return request({
    url: '/api/v1/generator/template/findPage',
    method: 'get',
    params: data,
  });
}

export function doInsert(data: TemplateDetail): Promise<AxiosResponse<any>> {
  return request({
    url: '/api/v1/generator/template/insertAndDetail',
    method: 'post',
    data,
  });
}

export function doUpdate(data: TemplateDetail): Promise<AxiosResponse<any>> {
  return request({
    url: '/api/v1/generator/template/updateAndDetail',
    method: 'post',
    data,
  });
}

export function doCopy(data: TemplateDetail): Promise<AxiosResponse<any>> {
  return request({
    url: '/api/v1/generator/template/copy',
    method: 'post',
    data,
  });
}

export function doDelete(data: { id: string | number }): Promise<AxiosResponse<any>> {
  return request({
    url: '/api/v1/generator/template/del',
    method: 'post',
    params: data,
  });
} 